package com.ruoyi.security.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.security.domain.AfRescue;
import com.ruoyi.security.service.IAfRescueService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 应急救援Controller
 *
 * @author cjie
 * @date 2021-07-24
 */
@Api(tags = " 应急救援")
@RestController
@RequestMapping("/afRescue")
public class AfRescueController extends BaseController {
    @Autowired
    private IAfRescueService afRescueService;

    /**
     * 查询应急救援列表
     */
    @ApiOperation(value="查询应急救援列表", notes="查询应急救援列表")
    @PreAuthorize(hasPermi = "security:afRescue:list")
    @GetMapping("/list")
    public TableDataInfo list(AfRescue afRescue) {
        startPage();
        List<AfRescue> list = afRescueService.selectAfRescueList(afRescue);
        return getDataTable(list);
    }

    /**
     * 导出应急救援列表
     */
    @ApiOperation(value="导出应急救援列表", notes="导出应急救援列表")
    @PreAuthorize(hasPermi = "security:afRescue:export")
    @Log(title = "应急救援", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AfRescue afRescue) throws IOException {
        List<AfRescue> list = afRescueService.selectAfRescueList(afRescue);
        ExcelUtil<AfRescue> util = new ExcelUtil<AfRescue>(AfRescue.class);
        util.exportExcel(response, list, "应急救援数据");
    }
    /**
     * 获取应急救援详细信息
     */
    @ApiOperation(value="获取应急救援详细信息", notes="获取应急救援详细信息")
    @PreAuthorize(hasPermi = "security:afRescue:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(afRescueService.selectAfRescueById(id));
    }

    /**
     * 新增应急救援
     */
    @ApiOperation(value="新增应急救援", notes="新增应急救援")
    @PreAuthorize(hasPermi = "security:afRescue:add")
    @Log(title = "应急救援", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AfRescue afRescue) {
        return toAjax(afRescueService.insertAfRescue(afRescue));
    }

    /**
     * 修改应急救援
     */
    @ApiOperation(value="修改应急救援", notes="修改应急救援")
    @PreAuthorize(hasPermi = "security:afRescue:edit")
    @Log(title = "应急救援", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AfRescue afRescue) {
        return toAjax(afRescueService.updateAfRescue(afRescue));
    }

    /**
     * 删除应急救援
     */
    @ApiOperation(value="删除应急救援", notes="删除应急救援")
    @ApiImplicitParam(name = "ids", value = "应急救援ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "security:afRescue:remove")
    @Log(title = "应急救援", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(afRescueService.deleteAfRescueByIds(ids));
    }
}
